import qs from 'qs';
import request from '@/utils/request'


/*对象转json*/
export function toJson(data) {
    var json = qs.stringify(data);
    return json;
}

/* apihandle */
export function apiHandle(url, id = 0) {
    let status = false;
    if (id > 0) {
        status = true;
        url += '/' + id
    }
    return {url: url, status: status}; // 编辑则为false
}

/*判断是否为空*/
export function isEmpty(str) {
    if (str === '' || str === null || str === undefined) {
        return true;
    }
    return false;
}

/**
 * get方法，对应get请求
 * @param {String} url [请求的url地址]
 * @param {Object} params [请求时携带的参数]
 */
export function get(url, params) {
    return request({
        url: url,
        method: 'get',
        params
    })
}
export function post(url, data) {
    return request({
        url: url,
        method: 'post',
        data
    })
}
export function put(url, data) {
    return request({
        url: url,
        method: 'put',
        data
    })
}

export function deletes(url, params) {
    return request({
        url: url,
        method: 'delete',
        params
    })
}